@extends('agent.mainlayout')
@section('title')
    <div class="title"><span>订单管理></span></div>
@endsection

@section('content')
        <!-- start 订单管理-->
    <style type="text/css">
        #sousuo{
            display:inline-block;
            background: #347c1e;
            color:white;
            height:25px;
            margin-left: 40px;
            cursor: pointer;
        }
        #sousuo:hover{
            background-color: #2d94e8;
        }
        .fixed_fahuo{
            position: absolute;
            left:50%;
            top:50%;
            margin-left: -230px;
            margin-top: -300px;
            width: 460px;
            height: 650px;
            background: white;
            box-sizing: border-box;
            padding: 10px 30px;
            font-size: 15px;
        }
        .fixed_fahuo h3{
            margin-top: 12px;
            font-size: 16px;
            padding-bottom: 10px;
            border-bottom: 1px solid #cccccc;
            color: rgb(59,174,218);
            font-weight: 600;
        }
        .fixed_fahuo .one{
            font-size: 14px;
            margin-top: 12px;
            overflow: hidden;
        }

        .fixed_fahuo .one p{
            float: left;
            line-height: 27px;
            margin-right: 30px;
            text-align: right;
        }
        .fixed_fahuo .two input{
            width: 240px;
            height: 30px;
            box-sizing: border-box;
            padding-left: 6px;
        }
        .fixed_fahuo .two{
            margin-top: 25px;
            font-size: 14px;
        }
        .fixed_fahuo .two p{
            height:28px;
            float: left;
            line-height: 27px;
            width: 60px;
            margin-right: 20px;
            text-align: left;
        }
        .fixed_fahuo .footer{
            margin-top: 30px;
            padding-left: 80px;
        }
        .fixed_fahuo .footer p{
            font-size: 14px;
            width: 76px;
            height: 32px;
            line-height: 32px;
            text-align: center;
            float: left;
            cursor: pointer;
            -webkit-user-select:none;
            -moz-user-select:none;
            -ms-user-select:none;
            user-select:none;
        }
        .fixed_fahuo .footer p:first-child{
            background: rgb(54,188,155);
            color: white;
        }
        .fixed_fahuo .footer p:last-child{
            margin-left: 12px;
            background: rgb(200,200,200);
            color: white;
        }
    </style>
    <div class="list4" style="display: ">
        <div class="header">
            <a href="{{url('center/order?p=0&status=0')}}"><p class="active">待发货</p></a>
            {{--<a href="{{url('center/order?p=1&status=1')}}"><p>已发货</p></a>--}}
            <a href="{{url('center/order?p=2&status=1')}}"><p>已发货</p></a>
        </div>
        <div class="main_top" >
            <form id='search' action="{{url('center/order')}}" method="get">
                <span>选择时间段</span>
                <input type="hidden" name="p" value="0"/>
                <input type="hidden" name="status" value="0"/>
                <input type="text" name="starttime" class="laydate-icon" id="hello2"/> <span>到</span>
                <input type="text" name="endtime" class="laydate-icon" id="hello3"/>
                <span id="sousuo">提交</span>
            </form>
        </div>
        <!--待发货table-->
        <table class="tab_two" id="kuxuan">
            <tr>
                <th>订单号</th>
                <th>购买人</th>
                <th>商品名称</th>
                <th>商品价格</th>
                <th>商品数量</th>
                <th>应付总金额</th>
                <th>下单时间</th>
                <th>操作</th>
            </tr>
            @if(!empty($res['data']))
                @foreach($res['data'] as $v)
            <tr>
                <td>{{$v['order_sn']}}</td>
                <td>{{$v['name']}}</td>
                <td>{{$v['goods_name']}}</td>
                <td>{{$v['goods_price']}}</td>
                <td>{{$v['goods_num']}}</td>
                <td>{{$v['pay_money']}}</td>
                <td>{{$v['created_at']}}</td>

                <td><span onclick="bandFangweima({{$v['goods_id']}},{{$v['id']}});" id="bangding">绑定防伪码</span>
                    &nbsp
                    <span id="fahuo" person="{{$v['name']}}" address="{{$v['address']}}" goods_id="{{$v['id']}}" onclick="faHuo(this);" order_sn="{{$v['order_sn']}}" goods_name="{{$v['goods_name']}}" goods_price="{{$v['goods_price']}}" goods_num="{{$v['goods_num']}}" discount="{{$v['discount']}}" total_money="{{$v['total_money']}}" pay_money="{{$v['pay_money']}}" remark="{{$v['remark']}}">发货</span>
                <a style="margin-left: 10px;" href="{{urlAdmin('Order','getOrderDetail',['id'=>$v['id']])}}"><span style="color:red">查看详情</span></a>
                </td>

            </tr>
                @endforeach
            @else
                <tr>
                    <td colspan="9">暂无数据...</td>
                </tr>
            @endif
        </table>

        <div class="del">
            @if(isset($res['last_page'])&&$res['last_page']>1)
            <div class="bot">
                @if($res['prev_page_url'])
                    <p class="prev"><a href="{{$res['prev_page_url']}}&p=0&status=0">上一页</a></p>
                @endif
                <ul>
                    @foreach($res['pageNoList'] as $v)
                        <li @if($res['current_page'] ==  $v )class="active_list" @endif ><a href="/center/order?p=0&status=0&page={{$v}}">{{$v}}</a></li>
                    @endforeach
                </ul>
                @if($res['next_page_url'])
                    <p class="next"><a href="{{$res['next_page_url']}}&p=0&status=0">下一页</a></p>
                @endif
            </div>
            @endif
        </div>
    </div>

    <div id="fixed" style="display:none ">
        <!-- start 绑定防伪码-->
        <div class="fixed_four bind" style="display: none">
            <div class="main_top"><h3>绑定防伪码</h3> <div class="right"><input type="text"/> <span>搜索</span></div></div>
            <div class="two">
                <textarea></textarea>
            </div>
            <div class="footer">
                <p id="queren" data-goods-id="" data-order-id="">确认</p>
                <p id="quxiao">取消</p>
                <p>不同防伪码，用逗号隔开</p>
            </div>
        </div>
        <!-- end 绑定防伪码-->
        <!-- start 发货-->
        <div class="fixed_fahuo" style="display: none">
            <h3>订单详情</h3>
            <div class="one">
                <p>商品名称： <span></span></p>
                <p>单号： <span></span></p>
                <p>商品单价： <span></span></p>
                <p>商品数量： <span></span></p>
                <p>折前订单总金额： <span></span></p>
                <p>会员折扣： <span></span>%</p>
                <p>折后总金额： <span></span></p>

                <input type="hidden" name="id" value="" >
            </div>
            <h3>收货信息</h3>
            <div class="one">
                <p>收货人： <span></span></p>
                <p>收货地址： <span></span></p>
                <input type="hidden" name="id" value="" >
            </div>
            <h3>备注信息</h3>
            <div class="two">
                <textarea readonly name="remark" style="margin: 0px; width: 375px; height: 79px;"></textarea>
            </div>
            <h3>快递信息</h3>
            <div class="two">
                <p>快递公司</p>
                <input type="text" id="sms" name="sms" value=""/>
            </div>
            <div class="two">
                <p>快递单号</p>
                <input type="text" id="Courier_number" name="Courier_number" value=""/>
            </div>
            <div class="footer">
                <p class="queren">确认发货</p>
                <p class="quxiao">取消</p>
            </div>
        </div>
        <!-- end 发货-->

    </div>
    <script>
        //绑定防伪码
        function bandFangweima(goods_id,order_id){

            //alert(id);
            $('.fixed_four').siblings().hide();
            //弹出弹窗
            $('#fixed').show();
            $('.fixed_four').show();

            var url = "{{url('center/securitycode/bulid')}}?goods_id="+goods_id+'&order_id='+order_id;

            $.ajax({
                type:"GET",
                url:url,
                dataType:"json",
                success:function(res){
                    $("#queren").attr('data-goods-id',goods_id);
                    $("#queren").attr('data-order-id',order_id);
                    $('.fixed_four').find('textarea').val(res.data);
                }
            });
        }
        $('#queren').click(function(){
            //隐藏弹窗
            $('#fixed').hide();
            $('.fixed_four').hide();

            //加载效果
            //layer.load(2, {shade: false});
            var goods_id = $(this).attr('data-goods-id');
            var order_id = $(this).attr('data-order-id');

            var securitycode = $('#fixed .fixed_four').find('textarea').val();
            //alert(securitycode);
            //发送ajax请求绑定防伪码
            var url = "{{url('center/securitycode/add')}}?goods_id="+goods_id+'&order_id='+order_id;
            $.ajax({
                type:"POST",
                url:url,
                data:{goods_id:goods_id,order_id:order_id,securitycode:securitycode},
                dataType:"json",
                success:function(res){

                    //关闭加载效果
                    //layer.closeAll("loading");

                    //console.log(res);
                    if (res['status']==200){
                        layer.msg(res.msg, {icon: 6});

                    }else{
                        layer.msg(res.msg, {icon: 5});
                    }



                }
            });

        });
        //*************防伪码**********//


        /************发货***************/

        function faHuo(_this){

            var person =$(_this).attr('person');
            var id = $(_this).attr('goods_id');

            var address = $(_this).attr('address');
            var remark = $(_this).attr('remark');


            var goods_name = $(_this).attr('goods_name');
            var order_sn = $(_this).attr('order_sn');
            var goods_price = $(_this).attr('goods_price');
            var goods_num = $(_this).attr('goods_num');
            var total_money = $(_this).attr('total_money');

            var discount = $(_this).attr('discount');
            var pay_money = $(_this).attr('pay_money');


            //console.log(person);
            //弹出弹窗
            $('.fixed_fahuo .one').find('span').eq(0).html(goods_name);
            $('.fixed_fahuo .one').find('span').eq(1).html(order_sn);
            $('.fixed_fahuo .one').find('span').eq(2).html(goods_price);
            $('.fixed_fahuo .one').find('span').eq(3).html(goods_num);
            $('.fixed_fahuo .one').find('span').eq(4).html(total_money);
            $('.fixed_fahuo .one').find('span').eq(5).html(discount);
            $('.fixed_fahuo .one').find('span').eq(6).html(pay_money);



            $('.fixed_fahuo .one').find('span').eq(7).html(person);
            $('.fixed_fahuo .one').find('span').eq(8).html(address);
            $('.fixed_fahuo .two').find('textarea').html(remark);

            $('#fixed').show();
            $('.fixed_fahuo').show();


            //确认发货
            $('#fixed .fixed_fahuo .footer .queren').click(function(){

                $('#fixed').hide();
                $('.fixed_fahuo').hide();


                var url = "{{url('center/order/send')}}";
                //获取填写的表单数据
                var sms = $('#sms').val();

                var Courier_number = $('#Courier_number').val();

                //var id = $('#fahuo').attr('goods_id');



                //发送ajax请求
                $.ajax({
                    type:"POST",
                    url:url,
                    data:{id:id,sms:sms,Courier_number:Courier_number},
                    dataType:"json",
                    success:function(res){

                        //关闭加载效果
                        //layer.closeAll("loading");

                        console.log(res);
                        if (res['status']==1){
                            layer.msg(res.msg, {icon: 6});
                            setTimeout("location.reload()",1500);
                        }else{
                            layer.msg(res.msg, {icon: 5});
                        }
                    }
                });
            });








        }




        /************发货***************/

            //发货


        window.onload = function(){



            //alert( $('form:hidden').size() );
            /*******start发货********/
            //弹出弹窗
//            $('#fahuo').click(function(){
//
//                var person =$(this).attr('person');
//                var id = $(this).attr('goods_id');
//                var address = $(this).attr('address');
//                //console.log(address);
//
//                $('.fixed_fahuo .one').find('span').eq(0).html(person);
//                $('.fixed_fahuo .one').find('span').eq(1).html(address);
//
//
//                $('#fixed').show();
//                $('.fixed_fahuo').show('slow');
//
//
//
//            });

            //确认发货




            /********所有ajax加载效果**********/
            $(document).ajaxStart(function(){

                //加载效果
                layer.load(2, {shade: false});

            }).ajaxStop(function(){

                //关闭加载效果
                layer.closeAll("loading");
            });
            /********所有ajax加载效果**********/

                //取消发货
            $('#fixed .fixed_fahuo .footer .quxiao').click(function(){

                $('#fixed').hide();
                $('.fixed_fahuo').hide();

                //清空内容
                $('.fixed_fahuo .one').find('span').eq(0).html('');
                $('.fixed_fahuo .one').find('span').eq(1).html('');
                $('#sms').val('');
                $('#Courier_number').val('');
                $('#Courier_number').val('');
            });

            /*******end发货**********/

            /*******start 防伪码********/






            {{--$('#bangding').click(function(){--}}
            {{--$('.fixed_four').siblings().hide();--}}
            {{--//弹出弹窗--}}
            {{--$('#fixed').show();--}}
            {{--$('.fixed_four').show('slow');--}}

            {{--var id = $(this).attr('bcd');--}}
            {{--//alert(id);--}}
            {{--//发送ajax请求生成防伪码--}}
            {{--var url = "{{url('center/securitycode/bulid')}}?id="+id;--}}

            {{--$.ajax({--}}
            {{--type:"GET",--}}
            {{--url:url,--}}
            {{--dataType:"json",--}}
            {{--success:function(res){--}}

            {{--$('.fixed_four').find('textarea').val(res.data);--}}

            {{--}--}}
            {{--});--}}



            {{--});--}}






            $('#quxiao').click(function(){

                $('#fixed').hide();
                $('.fixed_four').hide();

                //清空弹窗的值
                $('.fixed_four').find('textarea').val('');

            });

            /*******end 防伪码********/

            /****酷炫效果*****/
            var oTable = document.getElementById('kuxuan');
            var aLi = oTable.getElementsByTagName('tr');
            //var arr = ['red','blue','grey'];
            var str = '';
            for(var i=1;i<aLi.length;i++){

                //aLi[i].style.background = arr[i%3];

                aLi[i].onmouseover = function(){
                    str = this.style.background;      //将原来的颜色保存起来
                    this.style.background = '#2bdacf';
                }

                aLi[i].onmouseout = function(){
                    this.style.background = str;
                }

            }
            /****酷炫效果****/

            /****时间搜索****/
            var oSousuo = document.getElementById('sousuo');
            var oSearch = document.getElementById('search');

            oSousuo.onclick = function(){
                //加载效果
                layer.load(2, {shade: false});

                oSearch.submit();


            }
            /****时间搜索****/

            laydate({
                elem: '#hello2'
            });
            laydate({
                elem: '#hello3'
            });
        }

    </script>

@endsection
